﻿using GamFi.Admin.API.Application.Contracts.Chain.AddChain;
using GamFi.Admin.API.Application.Contracts.Chain.GetChains;
using GamFi.Admin.API.Application.Contracts.Chain.UpdateChain;
using GamFi.Admin.API.Application.Features.Queries.Chain.AddChain;
using GamFi.Admin.API.Application.Features.Queries.Chain.DeleteChain;
using GamFi.Admin.API.Application.Features.Queries.Chain.GetChains;
using GamFi.Admin.API.Application.Features.Queries.Chain.UpdateChain;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GamFi.Admin.API.WEB.Controllers;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class ChainController(IMediator mediator) : ControllerBase
{
    /// <summary>
    /// Возвращает все чейны
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns>Все чейны</returns>
    [HttpGet("GetChains")]
    public async Task<GetChainsResponse> GetChains([FromQuery] GetChainsRequest request, CancellationToken cancellationToken)
        => await mediator.Send(new GetChainsQuery(request), cancellationToken);

    /// <summary>
    /// Добавляет новый чейн
    /// </summary>
    /// <param name="request">Данные для нового чейна</param>
    /// <param name="cancellationToken"></param>
    /// <returns>Результат добавления</returns>
    [HttpPost("AddChain")]
    public async Task AddChain(AddChainRequest request, CancellationToken cancellationToken)
        => await mediator.Send(new AddChainCommand(request), cancellationToken);

    /// <summary>
    /// Изменяет существующий чейн
    /// </summary>
    /// <param name="request">Новые данные для чейна</param>
    /// <param name="cancellationToken"></param>
    /// <returns>Результат изменения</returns>
    [HttpPut("UpdateChain")]
    public async Task UpdateChain(UpdateChainRequest request, CancellationToken cancellationToken)
        => await mediator.Send(new UpdateChainCommand(request), cancellationToken);

    /// <summary>
    /// Удаляет чейн по его идентификатору
    /// </summary>
    /// <param name="id">Идентификатор чейна, который требуется удалить</param>
    /// <param name="cancellationToken"></param>
    /// <returns>Результат удаления</returns>
    [HttpDelete("DeleteChain/{id:guid}")]
    public async Task DeleteChain(Guid id, CancellationToken cancellationToken)
        => await mediator.Send(new DeleteChainCommand(id), cancellationToken);
}